import { createHash } from "crypto";

/**
 * 暴露一个MD5加密函数
 * @param password
 * @param salt
 */
export function encrypt(password: string, salt: string): string {
  const hash = createHash("md5");
  hash.update(password + salt);
  return hash.digest("hex");
}


/**
 * 生成唯一字符串，但是可能会有重复，因此需要校验唯一性
 */
export function generateUniqueString(len:number): string {
  const characters = '1234567890ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789';
  let uniqueString = '';
  for (let i = 0; i < len; i++) {
    const randomIndex = Math.floor(Math.random() * characters.length);
    uniqueString += characters[randomIndex];
  }
  return uniqueString;
}

export function isNumber(value: any): boolean {
  return typeof value === 'number';
}
